package tech.aistar.service.center.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.Address;
import tech.aistar.mapper.center.AddressMapper;
import tech.aistar.service.center.IAddressService;
import tech.aistar.service.position.IAreaService;
import tech.aistar.vo.AddressVo;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by 23827 on 2019/9/28.
 */
@Service
@Transactional
public class AddressServiceImpl implements IAddressService {
    @Autowired
    private AddressMapper addressMapper;
    @Autowired
    private IAreaService iAreaService;


    @Override
    public List<Address> findAll() {
        List<Address> list = addressMapper.findAll();
        return list;
    }

    @Override
    public Address delById(Integer id) {
        addressMapper.delById(id);

        return null;
    }

    @Override
    public Address insertAddress(Address address) {
        addressMapper.insertAddress(address);

        return address;
    }

    @Override
    public void updateAddress(Address address) {
        addressMapper.updateAddress(address);

    }

    @Override
    public Address findById(Integer id) {
        Address address = addressMapper.findById(id);
        return address;
    }

    @Override
    public List<AddressVo> selectAll(Integer userId) {
        return null;
    }

    @Override
    public Address updateById(Integer id) {
        addressMapper.updateById(id);
        return null;
    }

    @Override
    public Address changeAll() {
        addressMapper.changeAll();
        return null;
    }

    @Override
    public Address findByUserId(Integer user_id) {
        Address address = addressMapper.findByUserId(user_id);
        return address;
    }

    @Override
    public List<Address> findAllById(Integer user_id) {
        List<Address> addressList = addressMapper.findAllById(user_id);
        return addressList;
    }

    //地址省市区 - 第三方实体类
//    @Override
//    public List<AddressVo> selectAll(Integer useId) {
//
//        List<AddressVo> addressVoList = new ArrayList<>();
//        List<Address> addresses = addressMapper.findAll();
//        for (int i = 0; i <addresses.size() ; i++) {
//            AddressVo addressVo = new AddressVo();
//            Address add = addresses.get(i);
//            System.out.println(add.getAreaId());
//            ProvinceCityAreaQueryVo provinceCityAreaQueryVo = iAreaService.selectPCA(add.getAreaId());
//
//            Integer id = add.getId();
//            addressVo.setId(id);
//            Integer userId = add.getUserId();
//            addressVo.setUserId(userId);
//            String username = add.getUsername();
//            addressVo.setUsername(username);
//            String phoneNumber = add.getPhoneNumber();
//            addressVo.setPhoneNumber(phoneNumber);
//            String addressDeatil = add.getAddressDeatil();
//            addressVo.setAddressDeatil(addressDeatil);
//            Integer dataFlag = add.getDataFlag();
//            addressVo.setDataFlag(dataFlag);
//            Integer isDefault = add.getIsDefault();
//            addressVo.setIsDefault(isDefault);
//
//            addressVo.setAreaName(provinceCityAreaQueryVo.getaName());
//            addressVo.setCityName(provinceCityAreaQueryVo.getcName());
//            addressVo.setProvinceName(provinceCityAreaQueryVo.getpName());
//            addressVoList.add(addressVo);
//        }
//
//        return addressVoList;
//    }

}
